package net.flowas.genericcrud.rest;

import java.util.Map;

import javax.ws.rs.Path;

import net.flowas.genericcrud.audit.AuditResource;

public class CrudRestImpl implements CrudRest {

  private ItemsResource items = new ItemsResource();
  private I18nResource i18n = new I18nResource();
  private ReportResource report = new ReportResource();
  private ProfileResource profile = new ProfileResource();
  private FileResource file = new FileResource();
  private Map addons;

  @Path("/items")
  @Override
  public ItemsResource getItemsResource() {
    return items;
  }

  @Path("/i18n")
  @Override
  public I18nResource getI18nResource() {
    return i18n;
  }

  @Path("/reports")
  @Override
  public ReportResource getReportResource() {
    return report;
  }

  @Override
  public Object getAddon(String id) {
    if (addons == null) {
      throw new IllegalStateException("Addons is not initialized!");
    }
    Object addon = addons.get(id);
    if (addon == null) {
      throw new IllegalArgumentException("Addon with id[" + id + "] not found!");
    }
    return addon;
  }

  public void setAddons(Map addons) {
    this.addons = addons;
  }

  @Path("/profile")
  @Override
  public ProfileResource getProfileResource() {
    return profile;
  }

  @Path("/files")
  @Override
  public FileResource getFileResource() {
    return file;
  }

  @Override
  public AuditResource getAuditResource() {
	return (AuditResource) addons.get("audit");
  }
}
